package com.nc.mem;

import java.lang.reflect.Field;
import java.nio.ByteBuffer;

import org.slf4j.LoggerFactory;

public abstract class PrivateAccessor {

	public static final PrivateAccessor INSTANCE;

	static {
		PrivateAccessor pa;
		try {
			pa = (PrivateAccessor) GraphClassLoader.defineClass(PrivateAccessor.class.getClassLoader(), "accessor.bin").//
					newInstance();

		} catch (final Throwable err) {
			LoggerFactory.getLogger(PrivateAccessor.class).error("Unable to Load PrivateAccessor, we'll fall back to reflection", err);

			pa = null;
		}

		INSTANCE = pa;
	}

	public abstract Object allocateInstance(Class<?> clazz) throws InstantiationException;

	public abstract boolean getBoolean(Object ref, long offset);

	public abstract byte getByte(Object ref, long offset);

	public abstract char getChar(Object ref, long offset);

	public abstract double getDouble(Object ref, long offset);

	public abstract float getFloat(Object ref, long offset);

	public abstract int getInt(Object ref, long offset);

	public abstract long getLong(Object ref, long offset);

	public abstract Object getObject(Object ref, long offset);

	public abstract short getShort(Object ref, long offset);

	public abstract boolean isReallocationAvailable();

	public abstract long objectFieldOffset(Class<?> clazz, String field);

	public abstract long objectFieldOffset(Field field);

	public abstract void putBoolean(Object ref, long offset, boolean val);

	public abstract void putByte(Object ref, long offset, byte val);

	public abstract void putChar(Object ref, long offset, char val);

	public abstract void putDouble(Object ref, long offset, double val);

	public abstract void putFloat(Object ref, long offset, float val);

	public abstract void putInt(Object ref, long offset, int val);

	public abstract void putLong(Object ref, long offset, long val);

	public abstract void putObject(Object ref, long offset, Object val);

	public abstract void putShort(Object ref, long offset, short val);

	public abstract void reallocateMemory(ByteBuffer buffer, int moreBytes, boolean resizeLimit);

	public abstract void unmap(ByteBuffer buff);

}
